package com.albaba.designpattern.iterator.text_002;

/**
 * @Description: 具体迭代器
 * @Author zx
 * @Date 2025/2/25 17:07
 * @Version 1.0
 */
public class TopicIterator implements IteratorIterator<Topic> {

    // Topic数组
    private Topic[] topics;

    // 记录存储位置的游标
    private int position;

    public TopicIterator(Topic[] topics) {
        this.topics = topics;
        this.position = 0;
    }

    @Override
    public void reset() {
        this.position = 0;
    }

    @Override
    public Topic next() {
        return topics[position++];
    }

    @Override
    public Topic currentItem() {
        return topics[position];
    }

    @Override
    public boolean hasNext() {
        if (position >= topics.length) {
            return false;
        }
        return true;
    }
}
